﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Tomato.Cryptography
{
    public class Key
    {
        public Key(string text)
        {
            Text = text;
            hash = new HashConversion(MD5.Create()).ComputeHash(text);
        }


        private byte[] hash;

        public string Text { get; private set; }


        public byte[] GetKey(int length)
        {
            return GetBytes(length);
        }

        public byte[] GetIV(int length)
        {
            return GetBytes(length);
        }

        private byte[] GetBytes(int length)
        {
            byte[] bytes = new byte[(int)(length / 8)];

            for (int i = 0; i <= bytes.Length - 1; i++)
            {
                bytes[i] = hash[i % hash.Length];
            }

            return bytes;
        }
    }
}
